<?php
html::printPath(
    array(
        'orgSeminar.form-title' => '/org/orgSeminar/all', 
        $registration['seminar']['name'] => '/org/orgSeminar/display?id=' . $registration['seminar']['id'], 
        'orgSeminar.registrationList' => '/org/orgSeminar/registrationList?id=' . $registration['seminar']['id'],
        'registration.display-title' => ''
    )
);
$msg->printMessages();
var_dump($paymentAcceptance);
if (! $paymentAcceptance['confirmed_at']) {
	echo '<ul class="commandList" style="margin-top: 0.5em">';
	// TODO enable editing only if the registration is not closed
	echo '<li class="editLi">' . html::anchor('org/orgRegistration/edit?id=' . $registration['id'], text::get('registration-editThis')) . '</li>';
	if (registrationUtils::canBeCancelled($registration, $registration['seminar'], $paymentAcceptance)) {
	    echo '<li class="deleteLi"><a href="#" onclick="return openInDialog(\'cancellationDialog\', \'' . text::getEscaped('myRegistration.cancellation') . '\');">' . text::getEscaped('myRegistration.cancellation') . '</a></li>';
	}
	echo '</ul>';
}

// Cancellation dialog
echo '<div id="cancellationDialog" class="hidden">';

// If the registration is already paid, the money will be returned.
// echo '<p>' . text::getEscaped('myRegistration.returnMoneyIfCancelled') . '</p>';
// If the registration is not paid yet, just cancel it.
if (! $registration['paid_price']) {
    //echo '<p>' . text::getEscaped('myRegistration.regIsNotPaidYet') . '</p>';
}

$fb = new FormBuilder('registration', $registration);
$fb->setAction('/org/orgRegistration/cancel');
$fb->textarea('cancellation_reason')->required();
$fb->submitButton('myRegistration.cancelThis');
$fb->write();

echo '</div>';

registrationHelper::printWholeRegistration($registration);


echo '<h2>' . text::getEscaped('registration-historyList') . '</h2>';
echo '<p class="description">' . text::getEscaped('registration-historyList-desc') . '</p>';

if (! $registration['history']) {
	echo text::getEscaped('registration-noHistory');
}
else {
	function batchValueFunction($entity, $entityListField) {
		if ($entity['batch_code']) {
			return $entity['batch_code'] . ' <span style="font-size: x-small">(' . format::dateInterval($entity['begin_date'], $entity['end_date']) . '</span>)';
		}
		return null;
	}
	function categoryValueFunction($entity, $entityListField) {
		if ($entity['category_code']) {
			return $entity['category_code'] . ' <span style="font-size: x-small">(' . $entity['program_type_name'] . ' / ' . $entity['accommodation_type_name'] . ')</span>';
		}
		return null;
	}
	
	$elb = new EntityListBuilder('registration', $registration['history']);
	$elb->setId('historyTable');
	$elb->integer('version')->labelKey('registrationHistory.version');
	$elb->text('batch_code')->valueFunction('batchValueFunction');
	$elb->text('category_code')->valueFunction('categoryValueFunction');
	$elb->price('total_price', 'currency_code')->alignRight();
	$elb->price('price_paid', 'currency_code')->alignRight();
	$elb->price('extra_discount', 'currency_code');
	$elb->longText('extra_discount_reason');
	$elb->price('payment_on_arrival_fee', 'currency_code');
	$elb->price('cancellation_fee', 'currency_code');
	$elb->boolean('social_discount_applied');
	$elb->boolean('early_discount_applied');
	$elb->boolean('late_charge_applied');
	$elb->text('organization_name')->labelKey('payment_organization_id');
	$elb->text('payment_type')->l10n('registration.paymentType-short-', true);
	$elb->text('modified_by_id')->doubleValue('modified_by_first_name', 'modified_by_last_name')->labelKey('application.modified_by');
	$elb->timestamp('modified_at')->labelKey('application.modified_at');
	$elb->write();
	?>
	<script type="text/javascript">
	jQuery(document).ready(function () {
		removeEmptyColumns('historyTable');
	});
	</script>
	<?php
}
